import React,{useContext, useEffect} from 'react';
import { AuthContext } from '../App';

export default function Header(props) {

    const {authState,authDispatch} = useContext(AuthContext);
    

    const {
        isAuthenticated,
        user,
        
    } = authState;  

    

    return (
        
            

            <nav id="navgation" >
                <h1 href="#" className="logo">DAXIA`APP</h1>
                {
                    isAuthenticated?(
                        <div>
                            <h3>hello,{user?user.lastName + user.firstName:'游客，请登陆'}</h3>
                            <button onClick={() => {
                                    authDispatch({type:'LOGOUT'});
                                }}>Logout</button>
                        </div>
                        
                    ):''
                }
                

            </nav>
            
        
    )
}